'use strict';

module.exports = app => {
	// 序列化
	app.passport.serializeUser(async (ctx, _user) => {
		return {
			id: _user.id
		}
	});
	
	// 反序列化
	app.passport.deserializeUser(async (ctx, _user) => {
		if (_user) {
			const client = ctx.grpc.com.jstide.grpc.user.userService
		  	const { exception, user } = await client.getUserById({
		      arg: _user.id
		    });
		    if (exception) {
		      return
		    }
		    return user
		}
	});
};